package com.yupi.springbootinit.controller;


import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.util.StrUtil;
import cn.hutool.log.Log;
import com.yupi.springbootinit.common.QueryListWhenId;
import com.yupi.springbootinit.common.Result;
import com.yupi.springbootinit.emun.RedisEmnu;
import com.yupi.springbootinit.model.entity.ConurseClassify;
import com.yupi.springbootinit.model.vo.ConurseClassifyReponseBody;
import com.yupi.springbootinit.service.ConurseClassifyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Api(tags = "分类相关接口")
@RestController
@Slf4j
public class ConurseClassifyController {

    @Autowired
    private ConurseClassifyService conurseClassifyService;

    /**
     * 查找分类的列表
     * @Parent_id=0 代表的就是一级分类
     */
    @ApiOperation("查询一级分类")
    @GetMapping("/ccList")
    public Result<List<ConurseClassifyReponseBody>> ConurseClassifyBodyList() {
        return Result.success(conurseClassifyService.getConurseClassifyList());
    }

    /**
     * 查询指定分类下的二级分类
     *
     * @param queryListWhenId 实体(只有一个ID属性, 并且做了非空限制)
     * @exception MethodArgumentNotValidException 如果参数为空将报这个异常,然后被全局异常处理器处理
     */
    @ApiOperation("查询指定分类下的二级分类")
    @PostMapping("/secondList")
    public Result<List<ConurseClassifyReponseBody>> ConurseClassifyBodySecondList(@Valid @RequestBody QueryListWhenId queryListWhenId) {
        return Result.success(conurseClassifyService.getConurseClassifySecondList(queryListWhenId.getId()));
    }

    /**
     * 返回分类的Tree结构
     */
    @ApiOperation("返回分类树形结构")
    @GetMapping("/tree")
    public Result<List<Tree<String>>> ReadClassifyTreeList() {
        return conurseClassifyService.getClassifyTreeList();
    }
}
